<?php

/**
 * This is the model class for table "relationship".
 *
 * The followings are the available columns in table 'relationship':
 * @property integer $id
 * @property string $phone_1
 * @property string $phone_2
 * @property string $phone_3
 * @property string $address_1
 * @property string $address_2
 * @property string $address_3
 * @property string $facebook_1
 * @property string $facebook_2
 * @property string $facebook_3
 * @property string $googleplus_1
 * @property string $googleplus_2
 * @property string $skype_1
 * @property string $skype_2
 * @property string $zalo_1
 * @property string $zalo_2
 * @property string $created
 * @property string $modified
 * @property string $email_1
 * @property string $email_2
 * @property string $email_3
 */
class Relationship extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'relationship';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('phone_1, phone_2, phone_3', 'length', 'max'=>50),
			array('address_1, address_2, address_3, facebook_1, facebook_2, facebook_3, googleplus_1, googleplus_2, skype_1, skype_2, zalo_1, zalo_2, email_1, email_2, email_3', 'length', 'max'=>255),
			array('created, modified', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, phone_1, phone_2, phone_3, address_1, address_2, address_3, facebook_1, facebook_2, facebook_3, googleplus_1, googleplus_2, skype_1, skype_2, zalo_1, zalo_2, created, modified, email_1, email_2, email_3', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'phone_1' => 'Phone 1',
			'phone_2' => 'Phone 2',
			'phone_3' => 'Phone 3',
			'address_1' => 'Address 1',
			'address_2' => 'Address 2',
			'address_3' => 'Address 3',
			'facebook_1' => 'Facebook 1',
			'facebook_2' => 'Facebook 2',
			'facebook_3' => 'Facebook 3',
			'googleplus_1' => 'Googleplus 1',
			'googleplus_2' => 'Googleplus 2',
			'skype_1' => 'Skype 1',
			'skype_2' => 'Skype 2',
			'zalo_1' => 'Zalo 1',
			'zalo_2' => 'Zalo 2',
			'created' => 'Created',
			'modified' => 'Modified',
			'email_1' => 'Email 1',
			'email_2' => 'Email 2',
			'email_3' => 'Email 3',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('phone_1',$this->phone_1,true);
		$criteria->compare('phone_2',$this->phone_2,true);
		$criteria->compare('phone_3',$this->phone_3,true);
		$criteria->compare('address_1',$this->address_1,true);
		$criteria->compare('address_2',$this->address_2,true);
		$criteria->compare('address_3',$this->address_3,true);
		$criteria->compare('facebook_1',$this->facebook_1,true);
		$criteria->compare('facebook_2',$this->facebook_2,true);
		$criteria->compare('facebook_3',$this->facebook_3,true);
		$criteria->compare('googleplus_1',$this->googleplus_1,true);
		$criteria->compare('googleplus_2',$this->googleplus_2,true);
		$criteria->compare('skype_1',$this->skype_1,true);
		$criteria->compare('skype_2',$this->skype_2,true);
		$criteria->compare('zalo_1',$this->zalo_1,true);
		$criteria->compare('zalo_2',$this->zalo_2,true);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('modified',$this->modified,true);
		$criteria->compare('email_1',$this->email_1,true);
		$criteria->compare('email_2',$this->email_2,true);
		$criteria->compare('email_3',$this->email_3,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Relationship the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function behaviors()
	{
		return array('CTimestampBehavior' => array(
				'class' => 'zii.behaviors.CTimestampBehavior',
				'createAttribute' => 'created',
				'updateAttribute' => 'modified',
				'setUpdateOnCreate' => 'true',
			),
		);
	}
}
